package com.kzd.gtboon.main.service

import android.view.LayoutInflater
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.kzd.gtboon.R
import com.kzd.gtboon.databinding.ActivityProblemDetailsBinding
import com.kzd.gtboon.main.KEY_PROBLEM_ACTION
import com.kzd.gtboon.main.ProblemDetailsAction
import com.module.lemlin.app.OwnerStatusBar
import com.module.lemlin.owner.OwnerViewBindingActivity

class ProblemDetailsActivity : OwnerViewBindingActivity<ActivityProblemDetailsBinding>() {

    data class Problem(
        val title: String, val content: String,
    )

    private val mProblemPlatformList: MutableList<Problem> by lazy {
        mutableListOf(
            Problem(
                getString(R.string.problem_details_platform_1_title),
                getString(R.string.problem_details_platform_1)
            ),
            Problem(
                getString(R.string.problem_details_platform_2_title),
                getString(R.string.problem_details_platform_2)
            ),
            Problem(
                getString(R.string.problem_details_platform_3_title),
                getString(R.string.problem_details_platform_3)
            ),
            Problem(
                getString(R.string.problem_details_platform_4_title),
                getString(R.string.problem_details_platform_4)
            )
        )
    }

    private val mProblemGameList: MutableList<Problem> by lazy {
        mutableListOf(
            Problem(
                getString(R.string.problem_details_game_1_title),
                getString(R.string.problem_details_game_1)
            ),
            Problem(
                getString(R.string.problem_details_game_2_title),
                getString(R.string.problem_details_game_2)
            ),
            Problem(
                getString(R.string.problem_details_game_3_title),
                getString(R.string.problem_details_game_3)
            ),
            Problem(
                getString(R.string.problem_details_game_4_title),
                getString(R.string.problem_details_game_4)
            ),
            Problem(
                getString(R.string.problem_details_game_5_title),
                getString(R.string.problem_details_game_5)
            ),
            Problem(
                getString(R.string.problem_details_game_6_title),
                getString(R.string.problem_details_game_6)
            )
        )
    }

    private val mProblemTransactionList: MutableList<Problem> by lazy {
        mutableListOf(
            Problem(
                getString(R.string.problem_details_transaction_1_title),
                getString(R.string.problem_details_transaction_1)
            ),
            Problem(
                getString(R.string.problem_details_transaction_2_title),
                getString(R.string.problem_details_transaction_2)
            ),
            Problem(
                getString(R.string.problem_details_transaction_3_title),
                getString(R.string.problem_details_transaction_3)
            ),
            Problem(
                getString(R.string.problem_details_transaction_4_title),
                getString(R.string.problem_details_transaction_4)
            )
        )
    }

    private val mProblemCurrencyList: MutableList<Problem> by lazy {
        mutableListOf(
            Problem(
                getString(R.string.problem_details_currency_1_title),
                getString(R.string.problem_details_currency_1)
            ),
            Problem(
                getString(R.string.problem_details_currency_2_title),
                getString(R.string.problem_details_currency_2)
            ),
            Problem(
                getString(R.string.problem_details_currency_3_title),
                getString(R.string.problem_details_currency_3)
            ),
            Problem(
                getString(R.string.problem_details_currency_4_title),
                getString(R.string.problem_details_currency_4)
            ),
            Problem(
                getString(R.string.problem_details_currency_5_title),
                getString(R.string.problem_details_currency_5)
            ),
            Problem(
                getString(R.string.problem_details_currency_6_title),
                getString(R.string.problem_details_currency_6)
            ),
            Problem(
                getString(R.string.problem_details_currency_7_title),
                getString(R.string.problem_details_currency_7)
            ),
            Problem(
                getString(R.string.problem_details_currency_8_title),
                getString(R.string.problem_details_currency_8)
            ),
            Problem(
                getString(R.string.problem_details_currency_9_title),
                getString(R.string.problem_details_currency_9)
            ),
            Problem(
                getString(R.string.problem_details_currency_10_title),
                getString(R.string.problem_details_currency_10)
            ),
            Problem(
                getString(R.string.problem_details_currency_11_title),
                getString(R.string.problem_details_currency_11)
            ),
            Problem(
                getString(R.string.problem_details_currency_12_title),
                getString(R.string.problem_details_currency_12)
            ),
            Problem(
                getString(R.string.problem_details_currency_13_title),
                getString(R.string.problem_details_currency_13)
            )
        )
    }

    private val mProblemMemberList: MutableList<Problem> by lazy {
        mutableListOf(
            Problem(
                getString(R.string.problem_details_member_1_title),
                getString(R.string.problem_details_member_1)
            ),
            Problem(
                getString(R.string.problem_details_member_2_title),
                getString(R.string.problem_details_member_2)
            ),
            Problem(
                getString(R.string.problem_details_member_3_title),
                getString(R.string.problem_details_member_3)
            ),
            Problem(
                getString(R.string.problem_details_member_4_title),
                getString(R.string.problem_details_member_4)
            ),
            Problem(
                getString(R.string.problem_details_member_5_title),
                getString(R.string.problem_details_member_5)
            )
        )
    }

    private val mProblemPlayList: MutableList<Problem> by lazy {
        mutableListOf(
            Problem(
                getString(R.string.problem_details_play_1_title),
                getString(R.string.problem_details_play_1)
            ),
            Problem(
                getString(R.string.problem_details_play_2_title),
                getString(R.string.problem_details_play_2)
            ),
            Problem(
                getString(R.string.problem_details_play_3_title),
                getString(R.string.problem_details_play_3)
            ),
            Problem(
                getString(R.string.problem_details_play_4_title),
                getString(R.string.problem_details_play_4)
            ),
        )
    }

    private val mProblemAwardList: MutableList<Problem> by lazy {
        mutableListOf(
            Problem(
                getString(R.string.problem_details_award_1_title),
                getString(R.string.problem_details_award_1)
            ),
            Problem(
                getString(R.string.problem_details_award_2_title),
                getString(R.string.problem_details_award_2)
            )
        )
    }

    private val mProblemDetailsAdapter =
        object : BaseQuickAdapter<Problem, BaseViewHolder>(R.layout.item_problem_details) {
            override fun convert(holder: BaseViewHolder, item: Problem) {
                holder.setText(R.id.tvProblemDetailsTitle, item.title)
                    .setText(R.id.tvProblemDetailsContent, item.content)
            }
        }

    private val mAction: ProblemDetailsAction by lazy {
        (intent?.extras?.getSerializable(KEY_PROBLEM_ACTION) as? ProblemDetailsAction)
            ?: ProblemDetailsAction.PLATFORM
    }

    override val inflate: (LayoutInflater) -> ActivityProblemDetailsBinding
        get() = ActivityProblemDetailsBinding::inflate

    override fun initStatusBar(statusBar: OwnerStatusBar) {
        statusBar.run {
            addView = mViewBinding.flProblemDetailsBar
        }
        super.initStatusBar(statusBar)
    }

    override fun initView() {

        mViewBinding.flProblemDetailsBar.setTitleTextContent(mAction.title)

        mViewBinding.rvProblemDetailsBody.adapter = mProblemDetailsAdapter
    }

    override fun initData() {

        val problemList = when (mAction) {
            ProblemDetailsAction.PLATFORM -> mProblemPlatformList
            ProblemDetailsAction.GAME -> mProblemGameList
            ProblemDetailsAction.TRANSACTION -> mProblemTransactionList
            ProblemDetailsAction.CURRENCY -> mProblemCurrencyList
            ProblemDetailsAction.MEMBER -> mProblemMemberList
            ProblemDetailsAction.PLAY -> mProblemPlayList
            ProblemDetailsAction.AWARD -> mProblemAwardList
        }
        mProblemDetailsAdapter.setNewInstance(problemList)
    }
}